$(function(){
  var key = getSearch().key;
  function render(){
      var param = {
        proName:key,
        page:1,
        pageSize:100
      }
      var $active = $(".search_sort li.active");
      if($active.length === 1){
        var $type = $active.data("type");
        var $value = $active.find("span").hasClass("fa-angle-up")?1:2;
        param[$type] = $value;  
      }  
    $.ajax({
      url:'/product/queryProduct',
      type:'get',
      data:param,
      success:function(info){
        // console.log(info);
        setTimeout(function(){
          $(".lt_product").html(template("tmp",info))
        },1000)
      }
    })
  } 
  $(".search_box input").val(key);
  render();

  // 点击按钮再次搜索
  $(".search_box button").on("click",function(){
    var key = $(".search_box input").val().trim();
    if(!key){
      mui.toast("请输入关键字");
      return;
    }
    window.location.href = "searchList.html?key="+key;
    
  })

  // 筛选
  $(".search_sort li[data-type]").on("click",function(){
    $this = $(this);
    if($this.hasClass("active")){
      $this.find("span").toggleClass("fa-angle-up").toggleClass("fa-angle-down");
      console.log(1);
    }else{
      $this.addClass("active").siblings().removeClass("active");
      $this.siblings().find("span").removeClass("fa-angle-up").addClass("fa-angle-down");
    }
    render();
  })
})